/*
 * AddNewColFrame.java
 *
 * --- Last Update: 6/19/2010 6:53 PM ---
 *
 * Update Notes 6/19/2010 6:53 PM by Adrian Wijasa:
 * Removed all uses of main.checkConnection methods. Before, the checkConnection method is used to let the
 * user enters his/her credentials whenever any info needs to be obtained from Database. Now, users have to
 * provide their credentials before AddNewColFrame is opened.
 *
 * Update Notes 4/17/2010 11:38 AM by Adrian Wijasa:
 * This version is made to work with Java 5.
 *
 * Update Notes 3/22/2010 8:25 PM by Adrian Wijasa:
 * Removed unused imports.
 *
 * Created on March 29, 2007, 3:58 PM
 *
 * CSV Loader
 * Copyright 2007, 2009, 2010 Adrian Wijasa
 *
 * This file is part of CSV Loader.
 *
 * CSV Loader is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CSV Loader is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CSV Loader.  If not, see <http://www.gnu.org/licenses/>.
 */

package forms;

import javax.swing.ButtonGroup;

/**
 *
 * @author matianyuan
 */
public class AddNewColFrame extends javax.swing.JFrame {

    /** Creates new form AddNewColFrame5 */
    public AddNewColFrame( Main main ) {
        this.main = main;
        cancel = true;
        initComponents();
        initRadioButtons();
        setLocation( main.getX() + 283, main.getY() + 240 );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pidmRadioButton = new javax.swing.JRadioButton();
        csbIDRadioButton = new javax.swing.JRadioButton();
        headerLabel = new javax.swing.JLabel();
        sjuIDRadioButton = new javax.swing.JRadioButton();
        okLabel = new javax.swing.JLabel();
        cancelButton = new javax.swing.JLabel();
        existingPIDMRadioButton = new javax.swing.JRadioButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("New Column");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        pidmRadioButton.setText("New PIDM");
        pidmRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        pidmRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        csbIDRadioButton.setText("New CSB ID");
        csbIDRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        csbIDRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        headerLabel.setText("The data to be displayed in this new column:");

        sjuIDRadioButton.setText("New SJU ID");
        sjuIDRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        sjuIDRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        okLabel.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        okLabel.setForeground(new java.awt.Color(0, 102, 255));
        okLabel.setText("OK");
        okLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                okLabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                okLabelMouseExited(evt);
            }
        });

        cancelButton.setFont(new java.awt.Font("Dialog", 1, 11)); // NOI18N
        cancelButton.setForeground(new java.awt.Color(0, 102, 255));
        cancelButton.setText("Cancel");
        cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cancelButtonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                cancelButtonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                cancelButtonMouseExited(evt);
            }
        });

        existingPIDMRadioButton.setText("Existing PIDM");
        existingPIDMRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        existingPIDMRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(csbIDRadioButton)
                            .add(layout.createSequentialGroup()
                                .add(pidmRadioButton)
                                .add(34, 34, 34)
                                .add(existingPIDMRadioButton))
                            .add(headerLabel)
                            .add(sjuIDRadioButton)))
                    .add(layout.createSequentialGroup()
                        .add(80, 80, 80)
                        .add(okLabel)
                        .add(33, 33, 33)
                        .add(cancelButton)))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(headerLabel)
                .add(6, 6, 6)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(pidmRadioButton)
                    .add(existingPIDMRadioButton))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(csbIDRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(sjuIDRadioButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(okLabel)
                    .add(cancelButton))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseClicked
        okLabel.setForeground( main.red );

        setVisible( false );

        if( pidmRadioButton.isSelected() ) {
            cancel = false;
            main.addNewPIDMCol();
            dispose();
        } else if( csbIDRadioButton.isSelected() ) {
            cancel = false;
            main.addNewCSBIDCol();;
            dispose();
        } else if( sjuIDRadioButton.isSelected() ) {
            cancel = false;
            main.addNewSJUIDCol();
            dispose();
        } else {
            cancel = false;
            new AddExistingPIDMFrame( main ).setVisible( true );
            dispose();
        }
}//GEN-LAST:event_okLabelMouseClicked

    private void okLabelMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseExited
        okLabel.setForeground( main.blue );
}//GEN-LAST:event_okLabelMouseExited

    private void okLabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okLabelMouseEntered
        okLabel.setForeground( main.black );
}//GEN-LAST:event_okLabelMouseEntered

    private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseClicked
        cancelButton.setForeground( main.red );
        dispose();
}//GEN-LAST:event_cancelButtonMouseClicked

    private void cancelButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseExited
        cancelButton.setForeground( main.blue );
}//GEN-LAST:event_cancelButtonMouseExited

    private void cancelButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelButtonMouseEntered
        cancelButton.setForeground( main.black );
}//GEN-LAST:event_cancelButtonMouseEntered

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        if( cancel ) {
            main.setEnabled( true );
            main.requestFocus();
        }
    }//GEN-LAST:event_formWindowClosed

    private void initRadioButtons() {
        newColButtonGroup = new ButtonGroup();
        
        newColButtonGroup.add( pidmRadioButton );
        newColButtonGroup.add( csbIDRadioButton );
        newColButtonGroup.add( sjuIDRadioButton );
        newColButtonGroup.add( existingPIDMRadioButton );

        pidmRadioButton.setSelected( true );
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel cancelButton;
    private javax.swing.JRadioButton csbIDRadioButton;
    private javax.swing.JRadioButton existingPIDMRadioButton;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JLabel okLabel;
    private javax.swing.JRadioButton pidmRadioButton;
    private javax.swing.JRadioButton sjuIDRadioButton;
    // End of variables declaration//GEN-END:variables

    private boolean cancel;
    private ButtonGroup newColButtonGroup;
    private Main main;
}
